import {
	defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import viteVueUnocss, {
	unocss,
	flex
} from './js_sdk/a-hua-unocss';

export default defineConfig({
	plugins: [
		uni(),
		viteVueUnocss({
			/** 预设数组；默认[unocss()] */
			presets: [
				unocss(),
				flex()
			],
			// prefix: ['uno'],
			/** 排除检测原子化 CSS 规则 */
			// exclude: ['node_modules', 'uni_modules'],
			/** 配置所有原子化 CSS 规则的默认单位 */
			// unit: 'rpx',

			shortcuts: {
				//竖直
				"fl-co": "flex flex-col",

				//竖直居中
				"fl-co-cen": "flex flex-col items-center",

				//水平居中
				"fl-ro-cen": "flex items-center",

				//justify : center
				"ju-cen": "justify-center",

				// justify : start
				"ju-sta": "justify-start",

				// justify : space-between
				"ju-bet": "justify-between",

				// justify : space-around
				"ju-aro": "justify-around",

				"b-safe": "bottom: env(safe-area-inset-bottom)",
			},


			rules: [
				//宽度
				//vh
				[/^wvh-(\d+)$/, (match) => ({
					width: `${match[1]}vh`
				})],


				//高度
				//vh
				[/^hvh-(\d+)$/, (match) => ({
					height: `${match[1]}vh`
				})],


				//padding
				//双向
				[/^p-(\d+)-(\d+)$/, (match) => ({
					padding: `${match[1]}rpx ${match[2]}rpx`
				})],
				//四向
				[/^p-(\d+)-(\d+)-(\d+)-(\d+)$/, (match) => ({
					padding: `${match[1]}rpx ${match[2]}rpx ${match[3]}rpx ${match[4]}rpx`
				})],
				//安全底部
				[/^pb-safe$/, () => ({
					"padding-bottom": "env(safe-area-inset-bottom)"
				})],


				//margin
				//双向
				[/^m-(\d+)-(\d+)$/, (match) => ({
					margin: `${match[1]}rpx ${match[2]}rpx`
				})],
				//四向
				[/^m-(\d+)-(\d+)-(\d+)-(\d+)$/, (match) => ({
					margin: `${match[1]}rpx ${match[2]}rpx ${match[3]}rpx ${match[4]}rpx`
				})],
				//安全底部
				[/^mb-safe$/, () => ({
					"margin-bottom": "env(safe-area-inset-bottom)"
				})],


				//material-shadow
				[/^material-shadow$/, () => ({
					"box-shadow": "0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0 1px 5px 0 rgb(0 0 0 / 12%)"
				})],

				//shadow
				[/^sd-(\d+)-(\d+)-(\d+)-(\d+)$/, ([, r, g, b, a]) => ({
					'box-shadow': `0 0 8px rgba(${r}, ${g}, ${b}, ${a}%)`
				})],


				//border-bottom
				[/^bts-(\d+)$/, (match) => ({
					'border-top': `${match[1]}rpx solid #f0f0f0`
				})],

			],
			/** 主题配置 */
			theme: {
				/** 是否读取项目根目录 uni.scss 文件内容生成颜色预设 */
				generator: false,

				/** 自定义颜色预设 */
				colors: {
					teal: {
						500: '#14b8a6',
						100: '#ccfbf1',
						300: '#5eead4',
						400: '#2dd4bf',
						50: '#f0fdfa',
					},
					cyan: {
						500: '#06b6d4',
					},
					yellow: {
						50: '#fefce8'
					},
					amber: {
						100: '#fef3c7'
					},
					orange: {
						100: '#ffedd5',
						200: '#fed7aa',
						400: '#fb923c',
						500: '#f97316',
						600: '#ea580c',
					},
					emerald: {
						100: '#d1fae5',
						200: '#a7f3d0',
					}
				}
			}
		}),
	],
})